<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Returns a DateTime object representing this date</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="mongodate.construct.html">« MongoDate::__construct</a></li>
      <li style="float: right;"><a href="mongodate.tostring.html">MongoDate::__toString »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="class.mongodate.html">MongoDate</a></li>
    <li>Returns a DateTime object representing this date</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="mongodate.todatetime" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">MongoDate::toDateTime</h1>
  <p class="verinfo">(PECL mongo &gt;= 1.6.0)</p><p class="refpurpose"><span class="refname">MongoDate::toDateTime</span> &mdash; <span class="dc-title">Returns a DateTime object representing this date</span></p>

 </div>

 <div id="mongodate.todatetime-soft-deprecation-notice" class="soft-deprecation-notice">
  <blockquote class="sidebar">
   <p class="para">This extension that defines this method
is deprecated. Instead, the <a href="" class="link">MongoDB</a> extension should be used.
Alternatives to this method include:</p>
   <ul class="simplelist">
    <li class="member"><span class="methodname"><strong>MongoDB\BSON\UTCDateTime::toDateTime()</strong></span></li>
   </ul>
  </blockquote>
 </div>

 <div class="refsect1 description" id="refsect1-mongodate.todatetime-description">
  <h3 class="title">Description</h3>
  <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="methodname"><strong>MongoDate::toDateTime</strong></span>(): <span class="type"><span class="type DateTime">DateTime</span></span></div>

  <p class="para rdfs-comment">
   Returns the <strong class="classname">DateTime</strong> representation of this date. The
   returned <strong class="classname">DateTime</strong> will use the UTC time zone.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-mongodate.todatetime-parameters">
  <h3 class="title">Parameters</h3>
  <p class="para">This function has no parameters.</p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-mongodate.todatetime-returnvalues">
  <h3 class="title">Return Values</h3>
  <p class="para">
   This date as a <strong class="classname">DateTime</strong> object.
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-mongodate.todatetime-examples">
  <h3 class="title">Examples</h3>
  <div class="example" id="example-174">
   <p><strong>Example #1 <span class="function"><strong>MongoDate::toDateTime()</strong></span> example</strong></p>
   <div class="example-contents"><p>This example demonstrates creating a DateTime object from a MongoDate
   object.</p></div>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$d&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">MongoDate</span><span style="color: #007700">(</span><span style="color: #0000BB">strtotime</span><span style="color: #007700">(</span><span style="color: #DD0000">"2014-11-18&nbsp;11:01:25"</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(&nbsp;</span><span style="color: #0000BB">$d</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">toDateTime</span><span style="color: #007700">()&nbsp;);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
   </div>

   <div class="example-contents"><p>The above example will output
something similar to:</p></div>
   <div class="example-contents screen">
<div class="cdata"><pre>
class DateTime#2 (3) {
  public $date =&gt;
  string(26) &quot;2014-11-18 11:01:25.000000&quot;
  public $timezone_type =&gt;
  int(1)
  public $timezone =&gt;
  string(6) &quot;+00:00&quot;
}
</pre></div>
   </div>
  </div>
 </div>

</div></div></div></body></html>